//
//  B_ReleaseActivityVC.m
//  Application
//
//  Created by 薛小刚 on 2018/8/9.
//  Copyright © 2018年 薛小刚. All rights reserved.
//

#import "B_ReleaseActivityVC.h"
#import "B_AddressSelectedVC.h"
#import "XGPhotoManager.h"
#import "B_AddBankModel.h"
#import "B_ChangeDataFooterView.h"
#import "B_ChangeDataTVC.h"
#import "B_TextViewTVC.h"
#import "B_ReleaseActivityHeaderView.h"
#import "B_MineHeaderMoreView.h"
#import "B_ReleaseActivityTwoButtonTVC.h"
#import "XGDatePicker.h"
#import <MAMapKit/MAMapKit.h>



@interface B_ReleaseActivityVC ()<UITextFieldDelegate, UITextViewDelegate>
/// 最多图片上传数量
@property (nonatomic, assign) NSInteger count;

@property (nonatomic, strong) BaseTableView * mainView;
/// 图片数组
@property (nonatomic, strong) NSMutableArray * imageArray;

@property (nonatomic, strong) XGPhotoManager * photoManager;
/// 封面图片
@property (nonatomic, strong) UIImage * headerImage;

@property (nonatomic, strong) AMapPOI * poi;


@end

@implementation B_ReleaseActivityVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setTitle:@"发布活动"];
    WeakSelf(weSelf, self);
    self.imageArray = [NSMutableArray array];
    _count = 9;
    [self setRightTextBarButtonItemWithFrame:CGRectZero title:@"保存" titleColor:[UIColor color_pink] backImage:@"" selectBackImage:@"" action:^(GUIButton *button) {
        //TODO:保存
        [weSelf saveImage];
    }];
    self.view = self.mainView;
    B_AddBankModel * model0 = [B_AddBankModel initB_AddBankModelWithTitle:@"活动标题" placeholder:@"不超过30个字" mapword:@"活动标题" alert:@"请输入活动标题"];
    B_AddBankModel * model1 = [B_AddBankModel initB_AddBankModelWithTitle:@"" placeholder:@"请输入活动详情" mapword:@"活动详情" alert:@"请输入活动详情"];
    B_AddBankModel * model2 = [B_AddBankModel initB_AddBankModelWithTitle:@"活动地点" placeholder:@"请选择" mapword:@"活动地点" alert:@"请选择活动地点"];
    B_AddBankModel * model3 = [B_AddBankModel initB_AddBankModelWithTitle:@"活动时间" placeholder:@"开始时间" mapword:@"活动时间" alert:@"请选择开始时间"];
    model3.value_name = @"活动时间";
    B_AddBankModel * model4 = [B_AddBankModel initB_AddBankModelWithTitle:@"报名截止" placeholder:@"请选择" mapword:@"报名截止" alert:@"请选择报名截止时间"];
    B_AddBankModel * model5 = [B_AddBankModel initB_AddBankModelWithTitle:@"参与方式" placeholder:@"" mapword:@"参与方式" alert:@"请选择参与方式"];
    model5.value_name = @"1";
    B_AddBankModel * model6 = [B_AddBankModel initB_AddBankModelWithTitle:@"报名费用" placeholder:@"0" mapword:@"报名费用" alert:@"请输入报名费用"];
    B_AddBankModel * model7 = [B_AddBankModel initB_AddBankModelWithTitle:@"活动人数" placeholder:@"0" mapword:@"活动人数" alert:@"请输入活动人数"];
    B_AddBankModel * model8 = [B_AddBankModel initB_AddBankModelWithTitle:@"咨询电话" placeholder:@"请输入咨询电话" mapword:@"咨询电话" alert:@"请输入咨询电话"];
    
    NSArray * array0 = @[model0, model1];
    NSArray * array1 = @[model2, model3, model4];
    NSArray * array2 = @[model5, model6, model7, model8];
    
    self.dataArray = [NSMutableArray arrayWithObjects:array0, array1, array2, nil];
    
}


- (BaseTableView *)mainView {
    if (!_mainView) {
        WeakSelf(weSelf, self);
        _mainView = [[BaseTableView alloc] init];
        [_mainView setTableViewFrameWithTop:0 left:0 right:0 bottom:0];
        [_mainView.tableView registerNib:[UINib nibWithNibName:@"B_TextViewTVC" bundle:nil] forCellReuseIdentifier:@"B_TextViewTVC"];
        [_mainView.tableView registerNib:[UINib nibWithNibName:@"B_ChangeDataTVC" bundle:nil] forCellReuseIdentifier:@"B_ChangeDataTVC"];
        [_mainView.tableView registerNib:[UINib nibWithNibName:@"B_ReleaseActivityTwoButtonTVC" bundle:nil] forCellReuseIdentifier:@"B_ReleaseActivityTwoButtonTVC"];
        [_mainView.tableView registerNib:[UINib nibWithNibName:@"B_ReleaseActivityTwoButtonTVC" bundle:nil] forCellReuseIdentifier:@"B_ReleaseActivityTwoButtonTVC1"];
        _mainView.numberOfSectionsBlock = ^NSInteger(UITableView *tableView) {
            return weSelf.dataArray.count;
        };
        _mainView.numberOfRowsBlock = ^NSInteger(UITableView *tableView, NSInteger section) {
            return ((NSArray *)weSelf.dataArray[section]).count;
        };
        
        _mainView.heightForHeaderBlock = ^CGFloat(UITableView *tableView, NSInteger section) {
            if (section == 0) {
                return 230;
            }
            return 45;
        };
        _mainView.viewForHeaderBlock = ^UIView *(UITableView *tableView, NSInteger section) {
            if (section == 0) {
                B_ReleaseActivityHeaderView * headerView0 = [B_ReleaseActivityHeaderView initB_ReleaseActivityHeaderView];
                headerView0.B_imageView.image = weSelf.headerImage;
                headerView0.B_addAction = ^{
                    // TODO:选择图片
                    [weSelf alertViewWithTitle:@"请选择" message:@"" buttonsTitles:@[@"相机", @"从相册选择", @"取消"] action:^(NSInteger index) {
                        if (index == 0) {
                            [weSelf.photoManager openCamereWithController:weSelf withImage:^(UIImage *image) {
                                weSelf.headerImage = image;
                                [tableView reloadData];
                            }];
                        } else if (index == 1) {
                            [weSelf.photoManager openSinglePhotoWithController:weSelf withImage:^(UIImage *image) {
                                weSelf.headerImage = image;
                                [tableView reloadData];
                            }];
                        }
                    }];
                };
                return headerView0;
            } else {
                B_MineHeaderMoreView * header = [B_MineHeaderMoreView initB_MineHeaderMoreView];
                header.moreButton.hidden = YES;
//                UIImage * image = [UIImage getImageWithColor:[UIColor color_yellow] alp:1];
//                header.B_leftImageView.image = image;
                if (section == 1) {
                    header.B_titleLabel.text = @"活动信息";
                } else if (section == 2) {
                    header.B_titleLabel.text = @"活动设置";
                }
                header.B_titleLabel.textColor = [UIColor color_text_light_gray];
                header.backgroundColor = [UIColor color_content_background_color];
                return header;
            }
        };
        
        _mainView.heightForFooterBlock = ^CGFloat(UITableView *tableView, NSInteger section) {
            if (section == 0) {
                CGFloat height = (SCREEN_WIDTH - 50) / 5.;
                if (weSelf.imageArray.count >= weSelf.count) {
                    return height * (weSelf.imageArray.count % 5 == 0 ? weSelf.imageArray.count / 5 : weSelf.imageArray.count / 5 + 1) + 50;
                } else {
                    return height * ((weSelf.imageArray.count + 1) % 5 == 0 ? (weSelf.imageArray.count + 1) / 5 : (weSelf.imageArray.count + 1) / 5 + 1) + 50;
                }
            } else {
                return 10;
            }
        };
        _mainView.viewForFooterBlock = ^UIView *(UITableView *tableView, NSInteger section) {
            if (section == 0) {
                B_ChangeDataFooterView * view = [B_ChangeDataFooterView initB_ChangeDataFooterView];
                view.count = 5;
                view.imageArray = weSelf.imageArray;
                view.B_lineView.hidden = NO;
                if (weSelf.imageArray.count > 0) {
                    view.B_contentLabel.hidden = YES;
                } else {
                    view.B_contentLabel.text = [NSString stringWithFormat:@"请上传商品图片(最多%ld张)", weSelf.count];
                    view.B_contentLabel.hidden = NO;
                }
                __block NSMutableArray * imageArray = [NSMutableArray array];
                view.deleteAction = ^(NSIndexPath *indexPath) {
                    //                    [imageArray removeObjectAtIndex:indexPath.row];
                    [weSelf.photoManager deleteImageWithIndex:indexPath.row];
                    [weSelf.imageArray removeObjectAtIndex:indexPath.row];
                    [tableView reloadData];
                };
                view.collectionTapAction = ^(NSIndexPath *indexPath) {
                    if (weSelf.imageArray.count == weSelf.count) {
                        //TODO:查看大图
                        
                        
                    } else {
                        if (weSelf.imageArray.count == indexPath.row) { // 选在照片
                            [weSelf alertViewWithTitle:@"请选择" message:@"" buttonsTitles:@[@"相机", @"从相册选择", @"取消"] action:^(NSInteger index) {
                                if (index == 0) {
                                    [weSelf.photoManager openCamereWithController:weSelf withImage:^(UIImage *image) {
                                        [weSelf.imageArray addObject:image];
                                        [tableView reloadData];
                                    }];
                                } else if (index == 1) {
                                    [weSelf.photoManager openMorePhotosWithController:weSelf maxNum:weSelf.count withImage:^(NSArray *imageArr, NSArray *array) {
                                        [weSelf.imageArray removeAllObjects];
                                        [weSelf.imageArray addObjectsFromArray:imageArr];
                                        [tableView reloadData];
                                        imageArray = [NSMutableArray arrayWithArray:array];
                                    }];;
                                }
                            }];
                        } else {
                            //TODO:查看大图
                            
                        }
                    }
                };
                return view;
            }
            return nil;
        };
        
        _mainView.heightForRowBlock = ^CGFloat(UITableView *tableView, NSIndexPath *indexPath) {
            B_AddBankModel * model = weSelf.dataArray[indexPath.section][indexPath.row];
            if ([model.map_word isEqualToString:@"活动详情"]) {
                return 150;
            }
            return 68;
        };
        _mainView.cellForRowBlock = ^UITableViewCell *(UITableView *tableView, NSIndexPath *indexPath) {
            B_AddBankModel * model = weSelf.dataArray[indexPath.section][indexPath.row];
            if ([model.map_word isEqualToString:@"活动详情"]) {
                B_TextViewTVC * cell = [tableView dequeueReusableCellWithIdentifier:@"B_TextViewTVC" forIndexPath:indexPath];
                cell.B_TextView.placeholder = model.placeholder_name;
                cell.B_TextView.text = model.value_name;
                cell.B_TextView.delegate = weSelf;
                cell.B_TextView.tag = indexPath.section * 100 + indexPath.row;
                return cell;
            } else if ([model.map_word isEqualToString:@"活动时间"]) {
                B_ReleaseActivityTwoButtonTVC * cell = [tableView dequeueReusableCellWithIdentifier:@"B_ReleaseActivityTwoButtonTVC" forIndexPath:indexPath];
                
                cell.B_titleLabel.text = model.key_title;
                if (ISNULL(model.B_noneText0)) {
                    [cell.B_leftButton setTitleColor:[UIColor color_text_deep_gray] forState:UIControlStateNormal];
                    [cell.B_leftButton setTitle:@"开始时间" forState:UIControlStateNormal];
                } else {
                    [cell.B_leftButton setTitleColor:[UIColor color_text_light_gray] forState:UIControlStateNormal];
                    [cell.B_leftButton setTitle:model.B_noneText0 forState:UIControlStateNormal];
                }
                if (ISNULL(model.B_noneText1)) {
                    [cell.B_rightButton setTitleColor:[UIColor color_text_deep_gray] forState:UIControlStateNormal];
                    [cell.B_rightButton setTitle:@"结束时间" forState:UIControlStateNormal];
                } else {
                    [cell.B_rightButton setTitleColor:[UIColor color_text_light_gray] forState:UIControlStateNormal];
                    [cell.B_rightButton setTitle:model.B_noneText1 forState:UIControlStateNormal];
                }
                cell.B_buttonAction = ^(NSInteger index) {
                    if (index == 1) {       // 开始时间
                        XGDatePicker * pic = [[XGDatePicker alloc] initWithType:PGDatePickerModeDateHourMinute];
                        [pic showWithController:weSelf Date:^(NSString *date) {
                            model.B_noneText0 = date;
                            [weSelf.mainView.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
                        }];
                    } else  {               // 结束时间
                        XGDatePicker * pic = [[XGDatePicker alloc] initWithType:PGDatePickerModeDateHourMinute];
                        [pic showWithController:weSelf Date:^(NSString *date) {
                            model.B_noneText1 = date;
                            [weSelf.mainView.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
                        }];
                    }
                };
                return cell;
            } else if ([model.map_word isEqualToString:@"参与方式"]) {
                B_ReleaseActivityTwoButtonTVC * cell = [tableView dequeueReusableCellWithIdentifier:@"B_ReleaseActivityTwoButtonTVC1" forIndexPath:indexPath];
                [cell.B_leftButton setTitleColor:[UIColor color_text_light_gray] forState:UIControlStateNormal];
                [cell.B_leftButton setTitle:@"收费" forState:UIControlStateNormal];
                [cell.B_rightButton setTitleColor:[UIColor color_text_light_gray] forState:UIControlStateNormal];
                [cell.B_rightButton setTitle:@"免费" forState:UIControlStateNormal];
                cell.B_titleLabel.text = model.key_title;
                if ([model.value_name isEqualToString:@"1"]) {
                    cell.B_leftButton.backgroundColor = [UIColor color_pink];
                    cell.B_rightButton.backgroundColor = [UIColor color_text_deep_gray];
                } else {
                    cell.B_leftButton.backgroundColor = [UIColor color_text_deep_gray];
                    cell.B_rightButton.backgroundColor = [UIColor color_pink];
                }
                
                cell.B_buttonAction = ^(NSInteger index) {
                    if (index == 1) {
                        model.value_name = @"1";
                        for (NSArray * array in weSelf.dataArray) {
                            for (B_AddBankModel * model in array) {
                                if ([model.map_word isEqualToString:@"报名费用"]) {
                                    model.B_noneText0 = @"1";
                                    break;
                                }
                            }
                        }
                    } else  {
                        model.value_name = @"2";
                        for (NSArray * array in weSelf.dataArray) {
                            for (B_AddBankModel * model in array) {
                                if ([model.map_word isEqualToString:@"报名费用"]) {
                                    model.B_noneText0 = @"-1";
                                    break;
                                }
                            }
                        }
                    }
                    [weSelf.mainView.tableView reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationNone];
                };
                return cell;
            }
            B_ChangeDataTVC * cell = [tableView dequeueReusableCellWithIdentifier:@"B_ChangeDataTVC" forIndexPath:indexPath];
            cell.B_keyLabel.text = model.key_title;
            cell.B_textfield.placeholder = model.placeholder_name;
            cell.B_textfield.text = model.value_name;
            cell.B_textfield.userInteractionEnabled = YES;
            cell.B_rightLabel.hidden = YES;
            cell.B_rightImageView.hidden = YES;
            cell.B_textfield.textAlignment = NSTextAlignmentLeft;
            cell.B_textfield.delegate = weSelf;
            cell.B_textfield.userInteractionEnabled = YES;
            if ([model.map_word isEqualToString:@"活动标题"] || [model.map_word isEqualToString:@"咨询电话"]) {
                if ([model.map_word isEqualToString:@"活动标题"]) {
                    cell.B_textfield.textAlignment = NSTextAlignmentLeft;
                    cell.B_textfield.keyboardType = UIKeyboardTypeDefault;
                    
                } else {
                    cell.B_textfield.textAlignment = NSTextAlignmentRight;
                    cell.B_textfield.keyboardType = UIKeyboardTypeNumberPad;
                    
                }
                cell.B_rightLabel.hidden = YES;
            } else if ([model.map_word isEqualToString:@"报名费用"] || [model.map_word isEqualToString:@"活动人数"]) {
                cell.B_textfield.textAlignment = NSTextAlignmentRight;
                cell.B_rightLabel.hidden = NO;
                cell.B_rightImageView.hidden = YES;
                if ([model.map_word isEqualToString:@"报名费用"]) {
                    cell.B_rightLabel.text = @"元/人";
                    
                } else {
                    cell.B_rightLabel.text = @"人";
                }
                cell.B_textfield.keyboardType = UIKeyboardTypeNumberPad;
            } else if ([model.map_word isEqualToString:@"活动地点"] || [model.map_word isEqualToString:@"报名截止"]) {
                cell.B_textfield.textAlignment = NSTextAlignmentRight;
                cell.B_textfield.userInteractionEnabled = NO;
            }
            cell.B_textfield.tag = indexPath.section * 100 + indexPath.row;
            return cell;
        };
        
        /**
         TODO:表的选择的方法

         @param tableView 表
         @param indexPath indexPath
         @return 没有返回
         */
        _mainView.didSelectRow = ^(UITableView *tableView, NSIndexPath *indexPath) {
            
            B_AddBankModel * model = weSelf.dataArray[indexPath.section][indexPath.row];
            if ([model.map_word isEqualToString:@"活动地点"]) {
                B_AddressSelectedVC * address = [[B_AddressSelectedVC alloc] init];
                address.addressSelected = ^(AMapPOI *poi) {
                    weSelf.poi = poi;
                    model.value_name = [NSString stringWithFormat:@"%@%@%@%@", safeValue3(poi.province), safeValue3(poi.city), safeValue3(poi.district), safeValue3(poi.name)];
                    [tableView reloadData];
                    model.B_noneText0 = [NSString stringWithFormat:@"%f", poi.location.longitude];
                    model.B_noneText1 = [NSString stringWithFormat:@"%f", poi.location.latitude];
                };
                
                [weSelf pushNextViewController:address];
            } else if ([model.map_word isEqualToString:@"报名截止"]) {
                XGDatePicker * pic = [[XGDatePicker alloc] initWithType:PGDatePickerModeDateHourMinute];
                [pic showWithController:weSelf Date:^(NSString *date) {
                    model.value_name = date;//[date stringByReplacingOccurrencesOfString:@"-" withString:@"/"];
                    [tableView reloadData];
                }];
            }
        };
        
    }
    return _mainView;
}

- (XGPhotoManager *)photoManager {
    if (!_photoManager) {
        _photoManager = [[XGPhotoManager alloc] init];
    }
    return _photoManager;
}

- (void)textViewDidEndEditing:(UITextView *)textView {
    NSIndexPath * indexPath = [NSIndexPath indexPathForRow:textView.tag % 100 inSection:textView.tag / 100];
    B_AddBankModel * model = self.dataArray[indexPath.section][indexPath.row];
    model.value_name = textView.text;
}

- (void)textFieldDidEndEditing:(UITextField *)textField {
    NSIndexPath * indexPath = [NSIndexPath indexPathForRow:textField.tag % 100 inSection:textField.tag / 100];
    B_AddBankModel * model = self.dataArray[indexPath.section][indexPath.row];
    model.value_name = textField.text;
}

/**
 保存图片
 */
- (void) saveImage {
    for (NSArray * array in self.dataArray) {
        for (B_AddBankModel * model in array) {
            if ([model.map_word isEqualToString:@"活动时间"]) {
                if (ISNULL(model.B_noneText0)) {
                    [KeyWindow makeToast:@"请选择开始时间"];
                    return;
                }
                if (ISNULL(model.B_noneText1)) {
                    [KeyWindow makeToast:@"请选择结束时间"];
                    return;
                }
            } else if ([model.map_word isEqualToString:@"报名费用"]) {
                if ([model.B_noneText0 isEqualToString:@"1"]) {
                    if (ISNULL(model.value_name)) {
                        [KeyWindow makeToast:model.alert_message];
                        return;
                    }
                }
            } else {
                if (ISNULL(model.value_name)) {
                    [KeyWindow makeToast:model.alert_message];
                    return;
                }
            }
            
        }
    }
    if (ISNULL(self.headerImage)) {
        [KeyWindow makeToast:@"请先选择封面图片"];
        return;
    }
    if (self.imageArray.count == 0) {
        [KeyWindow makeToast:@"请选择图片"];
        return;
    }
    NSMutableArray * imageArray = [NSMutableArray array];
    [imageArray addObject:self.headerImage];
    [imageArray addObjectsFromArray:self.imageArray];
    
    WeakSelf(weSelf, self);
    [NetworkingManager UploadmoreTaskWithURL:[NSString stringWithFormat:@"%@/yearnfor/inter/activity/uploadActivityPicture", ServiceIp] imagesArray:imageArray parameterOfimages:@"files" parametersDict:nil compressionRatio:0.7 succeedBlock:^(NSDictionary *dict) {
        if ([dict[@"code"] isEqualToString:@"20010"]) {
            [weSelf saveData:dict[@"values"]];
        } else {
            [KeyWindow makeToast:dict[@"message"]];
        }
    } failedBlock:^(NSError *error) {
        [KeyWindow makeToast:@"服务器异常"];
    }];
    
}

/**
 TODO:保存数据
 */
- (void) saveData:(NSArray *) imageArray {
    NSMutableDictionary * dictionary = [NSMutableDictionary dictionary];
    for (NSArray * array in self.dataArray) {
        for (B_AddBankModel * model in array) {
            if ([model.map_word isEqualToString:@"活动标题"]) {
                [dictionary setObject:model.value_name forKey:@"activityTitle"];
            } else if ([model.map_word isEqualToString:@"活动详情"]) {
                [dictionary setObject:model.value_name forKey:@"activityInfo"];
            } else if ([model.map_word isEqualToString:@"活动地点"]) {
                [dictionary setObject:safeValue3(self.poi.province) forKey:@"province"];
                [dictionary setObject:safeValue3(self.poi.city) forKey:@"city"];
                [dictionary setObject:safeValue3(self.poi.district) forKey:@"district"];
                [dictionary setObject:safeValue3(self.poi.name) forKey:@"location"];
                [dictionary setObject:[NSString stringWithFormat:@"%f", self.poi.location.longitude] forKey:@"longitude"];
                [dictionary setObject:[NSString stringWithFormat:@"%f", self.poi.location.latitude] forKey:@"latitude"];
            } else if ([model.map_word isEqualToString:@"活动时间"]) {
                if (ISNULL(model.B_noneText0)) {
                    [KeyWindow makeToast:@"请选择开始时间"];
                    return;
                }
                if (ISNULL(model.B_noneText1)) {
                    [KeyWindow makeToast:@"请选择结束时间"];
                    return;
                }
                [dictionary setObject:[NSString stringWithFormat:@"%.0f", [NSObject getTimeStamp:model.B_noneText0]] forKey:@"startTime"];
                [dictionary setObject:[NSString stringWithFormat:@"%.0f", [NSObject getTimeStamp:model.B_noneText1]] forKey:@"overTime"];
            } else if ([model.map_word isEqualToString:@"参与方式"]) {
                [dictionary setObject:model.value_name forKey:@"activityType"];
            } else if ([model.map_word isEqualToString:@"报名费用"]) {
                if ([model.B_noneText0 isEqualToString:@"1"]) {
                    [dictionary setObject:model.value_name forKey:@"applyPrice"];
                } else {
                    [dictionary setObject:@"0" forKey:@"applyPrice"];
                }
            } else if ([model.map_word isEqualToString:@"活动人数"]) {
                [dictionary setObject:model.value_name forKey:@"applyNumber"];
            } else if ([model.map_word isEqualToString:@"咨询电话"]) {
                [dictionary setObject:model.value_name forKey:@"applyPhone"];
            } else if ([model.map_word isEqualToString:@"报名截止"]) {
                [dictionary setObject:[NSString stringWithFormat:@"%.0f", [NSObject getTimeStamp:model.value_name]] forKey:@"blockingTime"];
            }
        }
    }
    
    [dictionary setObject:getUserId() forKey:@"userId"];
    [dictionary setObject:imageArray[0] forKey:@"activityCover"];
    /// 图片数组
    NSMutableArray * arr = [NSMutableArray arrayWithArray:imageArray];
    [arr removeObjectAtIndex:0];
    [dictionary setObject:arr forKey:@"pictures"];
    HXLog(@"dic is %@", dictionary);
    WeakSelf(weSelf, self);
    [NetworkingManager postNetworkRequestWithUrlString:@"/yearnfor/inter/activity/addActivity" parameters:@{@"json" : [dictionary mj_JSONString]} isCache:NO succeed:^(id data) {
        if ([data[@"code"] isEqualToString:@"20005"]) {
            [KeyWindow makeToast:@"上传成功"];
            [weSelf dismissViewControllerAnimated:YES completion:nil];
        } else {
            [KeyWindow makeToast:data[@"message"]];
        }
    } fail:^(NSError *error) {
        [KeyWindow makeToast:@"服务器异常"];
    }];
    
    
}


//- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
//    B_AddressSelectedVC * address = [[B_AddressSelectedVC alloc] init];
//    address.addressSelected = ^(NSString *address, AMapGeoPoint *location) {
//        NSLog(@"address is %@ location is 经度  %f 纬度  %f", address, location.longitude, location.latitude);
//    };
//    [self pushNextViewController:address];
//}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


/**
 TODO:重写导航左侧按钮的点击事件
 */
- (void)leftNavigationAction {
    [super leftNavigationAction];
    [self dismissViewControllerAnimated:YES completion:nil];
}

@end
